using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VABKOPF
    {
        #region
        #endregion
        public void SetUpNewRow(ref DataRow dwReturn, DataRow dwInput)
        {

            switch (app.company)
            {
                case "FLT":
                    DataSet SResult = new DataSet();
                    SResult = QueryABKOPF(dwInput, 0);
                    dwReturn = SResult.Tables[0].Rows[0];
                    #region
                    dwReturn["ABKMANDANT"] = "00";
                    dwReturn["ABKAUFKRS"] = "  ";
                    dwReturn["ABKAUFLFD"] = "000255";
                    dwReturn["ABKAUFART"] = "GP";
                    dwReturn["ABKKUNDNR"] = "00000000";
                    dwReturn["ABKWERK"] = "   ";
                    dwReturn["ABKABT"] = "   ";
                    dwReturn["ABKVTRNR"] = "        ";
                    dwReturn["ABKAEDAT"] = "20071119";
                    dwReturn["ABKKDAUFTNR"] = "                    ";
                    dwReturn["ABKKDAUFDAT"] = "20071119";
                    dwReturn["ABKKDZEICH"] = "               ";
                    dwReturn["ABKKDSB"] = "        ";
                    dwReturn["ABKARTSB"] = "        ";
                    dwReturn["ABKORDER"] = "    ";
                    dwReturn["ABKSPED"] = "   ";
                    dwReturn["ABKVERSART"] = "   ";
                    dwReturn["ABKVERPART"] = "   ";
                    dwReturn["ABKVERSADR"] = "        ";
                    dwReturn["ABKDIVADR"] = "        ";
                    dwReturn["ABKBSTADR"] = "        ";
                    dwReturn["ABKBSTDAT"] = "0";
                    dwReturn["ABKRECHADR"] = "        ";
                    dwReturn["ABKAUFTTXT1"] = "                                                                ";
                    dwReturn["ABKAUFTTXT2"] = "                                                                ";
                    dwReturn["ABKZENTREG"] = "N";
                    dwReturn["ABKTEXTE11"] = "  ";
                    dwReturn["ABKTEXTE12"] = "  ";
                    dwReturn["ABKTEXTE13"] = "  ";
                    dwReturn["ABKTEXTE14"] = "  ";
                    dwReturn["ABKTEXTE21"] = "  ";
                    dwReturn["ABKTEXTE22"] = "  ";
                    dwReturn["ABKTEXTE23"] = "  ";
                    dwReturn["ABKTEXTE24"] = "  ";
                    dwReturn["ABKAENDZL"] = "0";
                    dwReturn["ABKAENDBEN"] = "        ";
                    dwReturn["ABKAENDDAT"] = "0";
                    dwReturn["ABKNEUBEN"] = "JESSIE  ";
                    dwReturn["ABKNEUDAT"] = "20071119";
                    dwReturn["ABKDIVARTKZ"] = "N";
                    dwReturn["ABKAGKKZ"] = " ";
                    dwReturn["ABKKDKONTR"] = "               ";
                    dwReturn["ABKSTKZL"] = "0";
                    dwReturn["ABKCOMPKZ"] = " ";
                    dwReturn["ABKFILLER"] = "                                                                       ";

                    #endregion
                    break;
                default:
                case "TST":
                case "SXN":
                case "YGR": 
                    #region====YGR======
                    dwReturn["ABKMANDANT"] = "00";
                    dwReturn["ABKAUFKRS"] = "  ";
                    dwReturn["ABKAUFLFD"] = "000000";
                    dwReturn["ABKAUFART"] = "  ";
                    dwReturn["ABKKUNDNR"] = "00000000";
                    dwReturn["ABKWERK"] = "   ";
                    dwReturn["ABKABT"] = "   ";
                    dwReturn["ABKVTRNR"] = "        ";
                    dwReturn["ABKAEDAT"] = "0";
                    dwReturn["ABKKDAUFTNR"] = "                    ";
                    dwReturn["ABKKDAUFDAT"] = "0";
                    dwReturn["ABKKDZEICH"] = "               ";
                    dwReturn["ABKKDSB"] = "        ";
                    dwReturn["ABKARTSB"] = "        ";
                    dwReturn["ABKORDER"] = "    ";
                    dwReturn["ABKSPED"] = "   ";
                    dwReturn["ABKVERSART"] = "   ";
                    dwReturn["ABKVERPART"] = "   ";
                    dwReturn["ABKVERSADR"] = "        ";
                    dwReturn["ABKDIVADR"] = "        ";
                    dwReturn["ABKBSTADR"] = "        ";
                    dwReturn["ABKBSTDAT"] = "0";
                    dwReturn["ABKRECHADR"] = "        ";
                    dwReturn["ABKAUFTTXT1"] = "                                                                ";
                    dwReturn["ABKAUFTTXT2"] = "                                                                ";
                    dwReturn["ABKZENTREG"] = "N";
                    dwReturn["ABKTEXTE11"] = "  ";
                    dwReturn["ABKTEXTE12"] = "  ";
                    dwReturn["ABKTEXTE13"] = "  ";
                    dwReturn["ABKTEXTE14"] = "  ";
                    dwReturn["ABKTEXTE21"] = "  ";
                    dwReturn["ABKTEXTE22"] = "  ";
                    dwReturn["ABKTEXTE23"] = "  ";
                    dwReturn["ABKTEXTE24"] = "  ";
                    dwReturn["ABKAENDZL"] = "0";
                    dwReturn["ABKAENDBEN"] = "        ";
                    dwReturn["ABKAENDDAT"] = "0";
                    dwReturn["ABKNEUBEN"] = "        ";
                    dwReturn["ABKNEUDAT"] = "0";
                    dwReturn["ABKDIVARTKZ"] = "N";
                    dwReturn["ABKAGKKZ"] = " ";
                    dwReturn["ABKKDKONTR"] = "               ";
                    dwReturn["ABKSTKZL"] = "0";
                    dwReturn["ABKCOMPKZ"] = " ";
                    dwReturn["ABKFILLER"] = "                                                                       ";
                    #endregion
                    break;
                case "JLT":
                    #region====JLT========
                    dwReturn["ABKMANDANT"] = "00";
                    dwReturn["ABKAUFKRS"] = "  ";
                    dwReturn["ABKAUFLFD"] = "000000";
                    dwReturn["ABKAUFART"] = "VA";
                    dwReturn["ABKKUNDNR"] = "00000000";
                    dwReturn["ABKWERK"] = "   ";
                    dwReturn["ABKABT"] = "   ";
                    dwReturn["ABKVTRNR"] = "        ";
                    dwReturn["ABKAEDAT"] = "0";
                    dwReturn["ABKKDAUFTNR"] = "                    ";
                    dwReturn["ABKKDAUFDAT"] = "0";
                    dwReturn["ABKKDZEICH"] = "               ";
                    dwReturn["ABKKDSB"] = "        ";
                    dwReturn["ABKARTSB"] = "        ";
                    dwReturn["ABKORDER"] = "    ";
                    dwReturn["ABKSPED"] = "   ";
                    dwReturn["ABKVERSART"] = "   ";
                    dwReturn["ABKVERPART"] = "   ";
                    dwReturn["ABKVERSADR"] = "        ";
                    dwReturn["ABKDIVADR"] = "        ";
                    dwReturn["ABKBSTADR"] = "        ";
                    dwReturn["ABKBSTDAT"] = "0";
                    dwReturn["ABKRECHADR"] = "        ";
                    dwReturn["ABKAUFTTXT1"] = "                                                                ";
                    dwReturn["ABKAUFTTXT2"] = "                                                                ";
                    dwReturn["ABKZENTREG"] = "N";
                    dwReturn["ABKTEXTE11"] = "  ";
                    dwReturn["ABKTEXTE12"] = "  ";
                    dwReturn["ABKTEXTE13"] = "  ";
                    dwReturn["ABKTEXTE14"] = "  ";
                    dwReturn["ABKTEXTE21"] = "  ";
                    dwReturn["ABKTEXTE22"] = "  ";
                    dwReturn["ABKTEXTE23"] = "  ";
                    dwReturn["ABKTEXTE24"] = "  ";
                    dwReturn["ABKAENDZL"] = "0";
                    dwReturn["ABKAENDBEN"] = "        ";
                    dwReturn["ABKAENDDAT"] = "0";
                    dwReturn["ABKNEUBEN"] = "        ";
                    dwReturn["ABKNEUDAT"] = "0";
                    dwReturn["ABKDIVARTKZ"] = "N";
                    dwReturn["ABKAGKKZ"] = " ";
                    dwReturn["ABKKDKONTR"] = "               ";
                    dwReturn["ABKSTKZL"] = "0";
                    dwReturn["ABKCOMPKZ"] = " ";
                    dwReturn["ABKFILLER"] = "                                                                       ";

                    #endregion
                    break;
            }
            INTEXDBC.MapData(true, ref dwReturn, dwInput);
            dwReturn["ABKFILLER"] = "                                                                       ";

        }
        public DataRow Convert2ABKOPF(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryABKOPF(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region====YGR======
                    dwReturn["ABKMANDANT"] = "00";
                    dwReturn["ABKAUFKRS"] = "  ";
                    dwReturn["ABKAUFLFD"] = "000000";
                    dwReturn["ABKAUFART"] = "  ";
                    dwReturn["ABKKUNDNR"] = "00000000";
                    dwReturn["ABKWERK"] = "   ";
                    dwReturn["ABKABT"] = "   ";
                    dwReturn["ABKVTRNR"] = "        ";
                    dwReturn["ABKAEDAT"] = "0";
                    dwReturn["ABKKDAUFTNR"] = "                    ";
                    dwReturn["ABKKDAUFDAT"] = "0";
                    dwReturn["ABKKDZEICH"] = "               ";
                    dwReturn["ABKKDSB"] = "        ";
                    dwReturn["ABKARTSB"] = "        ";
                    dwReturn["ABKORDER"] = "    ";
                    dwReturn["ABKSPED"] = "   ";
                    dwReturn["ABKVERSART"] = "   ";
                    dwReturn["ABKVERPART"] = "   ";
                    dwReturn["ABKVERSADR"] = "        ";
                    dwReturn["ABKDIVADR"] = "        ";
                    dwReturn["ABKBSTADR"] = "        ";
                    dwReturn["ABKBSTDAT"] = "0";
                    dwReturn["ABKRECHADR"] = "        ";
                    dwReturn["ABKAUFTTXT1"] = "                                                                ";
                    dwReturn["ABKAUFTTXT2"] = "                                                                ";
                    dwReturn["ABKZENTREG"] = "N";
                    dwReturn["ABKTEXTE11"] = "  ";
                    dwReturn["ABKTEXTE12"] = "  ";
                    dwReturn["ABKTEXTE13"] = "  ";
                    dwReturn["ABKTEXTE14"] = "  ";
                    dwReturn["ABKTEXTE21"] = "  ";
                    dwReturn["ABKTEXTE22"] = "  ";
                    dwReturn["ABKTEXTE23"] = "  ";
                    dwReturn["ABKTEXTE24"] = "  ";
                    dwReturn["ABKAENDZL"] = "0";
                    dwReturn["ABKAENDBEN"] = "        ";
                    dwReturn["ABKAENDDAT"] = "0";
                    dwReturn["ABKNEUBEN"] = "        ";
                    dwReturn["ABKNEUDAT"] = "0";
                    dwReturn["ABKDIVARTKZ"] = "N";
                    dwReturn["ABKAGKKZ"] = " ";
                    dwReturn["ABKKDKONTR"] = "               ";
                    dwReturn["ABKSTKZL"] = "0";
                    dwReturn["ABKCOMPKZ"] = " ";
                    dwReturn["ABKFILLER"] = "                                                                       ";
                    #endregion
                    break;
                case "JLT":
                    #region====JLT========
                    dwReturn["ABKMANDANT"] = "00";
                    dwReturn["ABKAUFKRS"] = "  ";
                    dwReturn["ABKAUFLFD"] = "000000";
                    dwReturn["ABKAUFART"] = "VA";
                    dwReturn["ABKKUNDNR"] = "00000000";
                    dwReturn["ABKWERK"] = "   ";
                    dwReturn["ABKABT"] = "   ";
                    dwReturn["ABKVTRNR"] = "        ";
                    dwReturn["ABKAEDAT"] = "0";
                    dwReturn["ABKKDAUFTNR"] = "                    ";
                    dwReturn["ABKKDAUFDAT"] = "0";
                    dwReturn["ABKKDZEICH"] = "               ";
                    dwReturn["ABKKDSB"] = "        ";
                    dwReturn["ABKARTSB"] = "        ";
                    dwReturn["ABKORDER"] = "    ";
                    dwReturn["ABKSPED"] = "   ";
                    dwReturn["ABKVERSART"] = "   ";
                    dwReturn["ABKVERPART"] = "   ";
                    dwReturn["ABKVERSADR"] = "        ";
                    dwReturn["ABKDIVADR"] = "        ";
                    dwReturn["ABKBSTADR"] = "        ";
                    dwReturn["ABKBSTDAT"] = "0";
                    dwReturn["ABKRECHADR"] = "        ";
                    dwReturn["ABKAUFTTXT1"] = "                                                                ";
                    dwReturn["ABKAUFTTXT2"] = "                                                                ";
                    dwReturn["ABKZENTREG"] = "N";
                    dwReturn["ABKTEXTE11"] = "  ";
                    dwReturn["ABKTEXTE12"] = "  ";
                    dwReturn["ABKTEXTE13"] = "  ";
                    dwReturn["ABKTEXTE14"] = "  ";
                    dwReturn["ABKTEXTE21"] = "  ";
                    dwReturn["ABKTEXTE22"] = "  ";
                    dwReturn["ABKTEXTE23"] = "  ";
                    dwReturn["ABKTEXTE24"] = "  ";
                    dwReturn["ABKAENDZL"] = "0";
                    dwReturn["ABKAENDBEN"] = "        ";
                    dwReturn["ABKAENDDAT"] = "0";
                    dwReturn["ABKNEUBEN"] = "        ";
                    dwReturn["ABKNEUDAT"] = "0";
                    dwReturn["ABKDIVARTKZ"] = "N";
                    dwReturn["ABKAGKKZ"] = " ";
                    dwReturn["ABKKDKONTR"] = "               ";
                    dwReturn["ABKSTKZL"] = "0";
                    dwReturn["ABKCOMPKZ"] = " ";
                    dwReturn["ABKFILLER"] = "                                                                       ";

                    #endregion
                    break;
                default:
                    #region====ITX========
                    #endregion
                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }

        public void UpdateABKOPF(DataRow dwData, string ITXDBVERSION = "50.24")
        {

            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                default:
                    or1.CommandText = "UPDATE ABKOPF SET ABKMANDANT=:ABKMANDANT:,ABKAUFKRS=:ABKAUFKRS:,ABKAUFLFD=:ABKAUFLFD:,ABKAUFART=:ABKAUFART:,ABKKUNDNR=:ABKKUNDNR:,ABKWERK=:ABKWERK:,ABKABT=:ABKABT:,ABKVTRNR=:ABKVTRNR:,ABKAEDAT=:ABKAEDAT:,ABKKDAUFTNR=:ABKKDAUFTNR:,ABKKDAUFDAT=:ABKKDAUFDAT:,ABKKDZEICH=:ABKKDZEICH:,ABKKDSB=:ABKKDSB:,ABKARTSB=:ABKARTSB:,ABKORDER=:ABKORDER:,ABKSPED=:ABKSPED:,ABKVERSART=:ABKVERSART:,ABKVERPART=:ABKVERPART:,ABKVERSADR=:ABKVERSADR:,ABKDIVADR=:ABKDIVADR:,ABKBSTADR=:ABKBSTADR:,ABKBSTDAT=:ABKBSTDAT:,ABKRECHADR=:ABKRECHADR:,ABKAUFTTXT1=:ABKAUFTTXT1:,ABKAUFTTXT2=:ABKAUFTTXT2:,ABKZENTREG=:ABKZENTREG:,ABKTEXTE11=:ABKTEXTE11:,ABKTEXTE12=:ABKTEXTE12:,ABKTEXTE13=:ABKTEXTE13:,ABKTEXTE14=:ABKTEXTE14:,ABKTEXTE21=:ABKTEXTE21:,ABKTEXTE22=:ABKTEXTE22:,ABKTEXTE23=:ABKTEXTE23:,ABKTEXTE24=:ABKTEXTE24:,ABKAENDZL=:ABKAENDZL:,ABKAENDBEN=:ABKAENDBEN:,ABKAENDDAT=:ABKAENDDAT:,ABKNEUBEN=:ABKNEUBEN:,ABKNEUDAT=:ABKNEUDAT:,ABKDIVARTKZ=:ABKDIVARTKZ:,ABKAGKKZ=:ABKAGKKZ:,ABKKDKONTR=:ABKKDKONTR:,ABKSTKZL=:ABKSTKZL:,ABKCOMPKZ=:ABKCOMPKZ:,ABKFILLER=:ABKFILLER:"
                          + " WHERE    ABKMANDANT=:ABKMANDANT: AND ABKAUFKRS=:ABKAUFKRS:  AND ABKAUFLFD=:ABKAUFLFD: ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case "FLT":
                    or1.CommandText = "UPDATE ABKOPF SET ABKMANDANT=:ABKMANDANT:,ABKAUFKRS=:ABKAUFKRS:,ABKAUFLFD=:ABKAUFLFD:,ABKAUFART=:ABKAUFART:,ABKKUNDNR=:ABKKUNDNR:,ABKWERK=:ABKWERK:,ABKABT=:ABKABT:,ABKVTRNR=:ABKVTRNR:,ABKAEDAT=:ABKAEDAT:,ABKKDAUFTNR=:ABKKDAUFTNR:,ABKKDAUFDAT=:ABKKDAUFDAT:,ABKKDZEICH=:ABKKDZEICH:,ABKKDSB=:ABKKDSB:,ABKARTSB=:ABKARTSB:,ABKORDER=:ABKORDER:,ABKSPED=:ABKSPED:,ABKVERSART=:ABKVERSART:,ABKVERPART=:ABKVERPART:,ABKVERSADR=:ABKVERSADR:,ABKDIVADR=:ABKDIVADR:,ABKBSTADR=:ABKBSTADR:,ABKBSTDAT=:ABKBSTDAT:,ABKRECHADR=:ABKRECHADR:,ABKAUFTTXT1=:ABKAUFTTXT1:,ABKAUFTTXT2=:ABKAUFTTXT2:,ABKZENTREG=:ABKZENTREG:,ABKTEXTE11=:ABKTEXTE11:,ABKTEXTE12=:ABKTEXTE12:,ABKTEXTE13=:ABKTEXTE13:,ABKTEXTE14=:ABKTEXTE14:,ABKTEXTE21=:ABKTEXTE21:,ABKTEXTE22=:ABKTEXTE22:,ABKTEXTE23=:ABKTEXTE23:,ABKTEXTE24=:ABKTEXTE24:,ABKAENDZL=:ABKAENDZL:,ABKAENDBEN=:ABKAENDBEN:,ABKAENDDAT=:ABKAENDDAT:,ABKNEUBEN=:ABKNEUBEN:,ABKNEUDAT=:ABKNEUDAT:,ABKDIVARTKZ=:ABKDIVARTKZ:,ABKAGKKZ=:ABKAGKKZ:,ABKKDKONTR=:ABKKDKONTR:,ABKSTKZL=:ABKSTKZL:,ABKCOMPKZ=:ABKCOMPKZ:,ABKFILLER=:ABKFILLER:"
                         + " WHERE  ABKMANDANT=:ABKMANDANT: AND ABKAUFKRS=:ABKAUFKRS:  AND ABKAUFLFD=:ABKAUFLFD: ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }
            Connect2Proxy(or1);
        }

        public void UABK02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE  ABKOPF A SET (ABKKDAUFTNR)=(SELECT VKPEXAUFKRS||'-'||SUBSTR(VKPEXAUFLFD,3,4)||'-'||VKPEXAUFPOS||'         ' FROM VKPOS X WHERE RTRIM(ABKKDAUFTNR) = X.VKPAUFKRS||'-'||SUBSTR(X.VKPEXAUFLFD,3,4)||'-'||X.VKPAUFPOS AND X.VKPSA<>'AJ') WHERE EXISTS (SELECT '1' FROM VKPOS T WHERE RTRIM(ABKKDAUFTNR) = T.VKPAUFKRS||'-'||SUBSTR(T.VKPEXAUFLFD,3,4)||'-'||T.VKPAUFPOS AND T.VKPSA<>'AJ')";
            Connect2Proxy(or1);
        }

        public void UABK03(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE ABKOPF SET ABKMANDANT=:ABKMANDANT:,ABKAUFKRS=:ABKAUFKRS:,ABKAUFLFD=:ABKAUFLFD:,ABKAUFART=:ABKAUFART:,ABKKUNDNR=:ABKKUNDNR:,ABKWERK=:ABKWERK:,ABKABT=:ABKABT:,ABKVTRNR=:ABKVTRNR:,ABKAEDAT=:ABKAEDAT:,ABKKDAUFTNR=:ABKKDAUFTNR:,ABKKDAUFDAT=:ABKKDAUFDAT:,ABKKDZEICH=:ABKKDZEICH:,ABKKDSB=:ABKKDSB:,ABKARTSB=:ABKARTSB:,ABKORDER=:ABKORDER:,ABKSPED=:ABKSPED:,ABKVERSART=:ABKVERSART:,ABKVERPART=:ABKVERPART:,ABKVERSADR=:ABKVERSADR:,ABKDIVADR=:ABKDIVADR:,ABKBSTADR=:ABKBSTADR:,ABKBSTDAT=:ABKBSTDAT:,ABKRECHADR=:ABKRECHADR:,ABKAUFTTXT1=:ABKAUFTTXT1:,ABKAUFTTXT2=:ABKAUFTTXT2:,ABKZENTREG=:ABKZENTREG:,ABKTEXTE11=:ABKTEXTE11:,ABKTEXTE12=:ABKTEXTE12:,ABKTEXTE13=:ABKTEXTE13:,ABKTEXTE14=:ABKTEXTE14:,ABKTEXTE21=:ABKTEXTE21:,ABKTEXTE22=:ABKTEXTE22:,ABKTEXTE23=:ABKTEXTE23:,ABKTEXTE24=:ABKTEXTE24:,ABKAENDZL=:ABKAENDZL:,ABKAENDBEN=:ABKAENDBEN:,ABKAENDDAT=:ABKAENDDAT:,ABKNEUBEN=:ABKNEUBEN:,ABKNEUDAT=:ABKNEUDAT:,ABKDIVARTKZ=:ABKDIVARTKZ:,ABKAGKKZ=:ABKAGKKZ:,ABKKDKONTR=:ABKKDKONTR:,ABKSTKZL=:ABKSTKZL:,ABKCOMPKZ=:ABKCOMPKZ:,ABKFILLER=:ABKFILLER:"
                        + " WHERE    ABKMANDANT=:ABKMANDANT: AND ABKAUFKRS=:ABKAUFKRS:  AND ABKAUFLFD=:ABKAUFLFD: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }
        public void UABK04(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE ABKOPF SET ABKARTSB=:ABKARTSB:"
                        + " WHERE    ABKMANDANT=:ABKMANDANT: AND ABKAUFKRS=:ABKAUFKRS:  AND ABKAUFLFD=:ABKAUFLFD: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }
        public void SaveABKOPF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryABKOPF(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapABKOPF(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertABKOPF(dwLocal, ITXDBVERSION);
            }
            UpdateABKOPF(dwLocal);
        }

        public DataSet QueryABKOPF(DataRow dwData, int option = 1)
        { 
            or1 = OracleDB.CreateCommand();
            // APZMANDANT  APZART APZVAR APZANRKRS APZALFDNR APZSTUFE
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ABKOPF WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    SResult = QABK01(dwData);
                    break;
                case 2:
                    or1.CommandText = "SELECT DISTINCT MAX(ABPSPGRD) AS ABKSPGRD,MAX(ABPGESSTA) AS ABKGESSTA, MAX(ABPLIEFDAT) AS ABKLIEFDAT,ABKMANDANT, ABKAUFKRS,ABKAUFLFD,"
                    + "MAX(ABPART) AS ABPART,MAX(FSABEZ) AS FSABEZ,MAX(LSLIEFNA) AS EXTPRODUCER,MAX(LSNAME1) AS EXTFTYNAME,MAX(ABPLIEFNR) AS ABPLIEFNR,ABPANRKR"
                    + ",ABPALFDNR FROM ABKOPF K"
                            + " RIGHT JOIN ABPOS P ON ABKAUFKRS=ABPAUFKRS AND ABKAUFLFD=ABPAUFLFD"
                            + " LEFT JOIN FSSTAMM M ON ABPART=FSART "
                            + " LEFT JOIN LIEFDAT M ON LSLIEFNR=ABPLIEFNR "
                            + " WHERE ABPMANDANT=:ABPMANDANT: AND ABPSPGRD=:ABPSPGRD:  AND ABPERLKZ=' '"
                            + " GROUP BY ABKMANDANT,ABKAUFKRS,ABKAUFLFD,ABPANRKR,ABPALFDNR";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

                    SResult = Connect2Proxy(or1);
                    break;
                case 3:
                    or1.CommandText = "SELECT * FROM ABKOPF WHERE ABKMANDANT=:ABKMANDANT: AND SUBSTR(ABKKDAUFTNR,1,8)=:ABKKDAUFTNR:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

                    SResult = Connect2Proxy(or1);
                    break;
                case 4:
                    or1.CommandText = "SELECT K.* FROM ABKOPF K "
                        + "JOIN ABPOS P ON K.ABKAUFKRS=P.ABPAUFKRS AND K.ABKAUFLFD=P.ABPAUFLFD"
                        + " JOIN FSSTAMM M ON P.ABPART=M.FSART"
                        + " WHERE FSMANDANT=:FSMANDANT: AND M.FSART=:FSART:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

                    SResult = Connect2Proxy(or1);
                    break;
                case 5:
                    or1.CommandText = "SELECT DISTINCT MAX(ABPSPGRD) AS ABKSPGRD,MAX(ABPGESSTA) AS ABKGESSTA, MAX(ABPLIEFDAT) AS ABKLIEFDAT,ABKMANDANT, ABKAUFKRS,ABKAUFLFD,"
                    + "MAX(ABPART) AS ABPART,MAX(FSABEZ) AS FSABEZ,MAX(LSLIEFNA) AS EXTPRODUCER,MAX(LSNAME1) AS EXTFTYNAME,MAX(ABPLIEFNR) AS ABPLIEFNR,ABPANRKR"
                    + ",ABPALFDNR FROM ABKOPF K"
                            + " RIGHT JOIN ABPOS P ON ABKAUFKRS=ABPAUFKRS AND ABKAUFLFD=ABPAUFLFD"
                            + " LEFT JOIN FSSTAMM M ON ABPART=FSART "
                            + " LEFT JOIN LIEFDAT M ON LSLIEFNR=ABPLIEFNR "
                            + " WHERE ABPMANDANT=:ABPMANDANT: AND ABPERLKZ=' '"
                            + " GROUP BY ABKMANDANT,ABKAUFKRS,ABKAUFLFD,ABPANRKR,ABPALFDNR";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

                    SResult = Connect2Proxy(or1);
                    break;
                case 6:
                    or1.CommandText = "SELECT * FROM ABKOPF WHERE   ABKKDAUFTNR LIKE '" + dwData["ABKKDAUFTNR"].ToString().Trim() + "%'";

                    SResult = Connect2Proxy(or1);
                    break;
                case 7:
                    or1.CommandText = "SELECT ABKAUFKRS,ABKAUFLFD,ABPAUFKRS,ABPAUFLFD,ABPAUFPOS,ABPSOLLMENGE5,ABPSOLLMENGE7"
                    + " FROM ABKOPF K JOIN ABPOS ON ABKMANDANT=ABPMANDANT AND ABKAUFKRS=ABPAUFKRS AND ABPAUFLFD=ABKAUFLFD"
                    + " WHERE ABKMANDANT=:ABKMANDANT: AND ABKAUFKRS=:ABKAUFKRS: AND ABKAUFLFD=:ABKAUFLFD:"
                    + " ORDER BY ABPAUFPOS DESC";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

                    SResult = Connect2Proxy(or1);
                    break;
                default:
                    break;
            }

            SResult.Tables[0]. TableName = TableName; 
            return SResult;
        }
        public DataSet QABK01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ABKOPF   "
                   + "  WHERE ABKMANDANT=:ABKMANDANT: AND ABKAUFKRS=:ABKAUFKRS: AND ABKAUFLFD=:ABKAUFLFD:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData); 
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public void DeleteABKOPF(DataRow dwData, int option = 1)
        {

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM ABKOPF WHERE  "
                    + "  ABKMANDANT=:ABKMANDANT AND ABKAUFKRS=:ABKAUFKRS AND ABKAUFLFD=:ABKAUFLFD";
                    or1.Parameters.Add("ABKMANDANT", OracleType.NVarChar).Value = dwData["ABKMANDANT"].ToString();
                    or1.Parameters.Add("ABKAUFKRS", OracleType.NVarChar).Value = dwData["ABKAUFKRS"].ToString();
                    or1.Parameters.Add("ABKAUFLFD", OracleType.NVarChar).Value = dwData["ABKAUFLFD"].ToString();
                    break;
            }
            Connect2Proxy(or1);
        }

        public void MapABKOPF(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }

        public void InsertABKOPF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            dwData["ABKNEUBEN"] = app.User;
            dwData["ABKNEUDAT"] = date;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                default:
                case "TST":
                case "SXN":
                case "YGR":
                    or1.CommandText = "INSERT INTO ABKOPF ( ABKMANDANT,ABKAUFKRS,ABKAUFLFD,ABKAUFART,ABKKUNDNR,ABKWERK,ABKABT,ABKVTRNR,ABKAEDAT,ABKKDAUFTNR,ABKKDAUFDAT,ABKKDZEICH,ABKKDSB,ABKARTSB,ABKORDER,ABKSPED,ABKVERSART,ABKVERPART,ABKVERSADR,ABKDIVADR,ABKBSTADR,ABKBSTDAT,ABKRECHADR,ABKAUFTTXT1,ABKAUFTTXT2,ABKZENTREG,ABKTEXTE11,ABKTEXTE12,ABKTEXTE13,ABKTEXTE14,ABKTEXTE21,ABKTEXTE22,ABKTEXTE23,ABKTEXTE24,ABKAENDZL,ABKAENDBEN,ABKAENDDAT,ABKNEUBEN,ABKNEUDAT,ABKDIVARTKZ,ABKAGKKZ,ABKKDKONTR,ABKSTKZL,ABKCOMPKZ,ABKFILLER)"
                    + " VALUES (:ABKMANDANT:,:ABKAUFKRS:,:ABKAUFLFD:,:ABKAUFART:,:ABKKUNDNR:,:ABKWERK:,:ABKABT:,:ABKVTRNR:,:ABKAEDAT:,:ABKKDAUFTNR:,:ABKKDAUFDAT:,:ABKKDZEICH:,:ABKKDSB:,:ABKARTSB:,:ABKORDER:,:ABKSPED:,:ABKVERSART:,:ABKVERPART:,:ABKVERSADR:,:ABKDIVADR:,:ABKBSTADR:,:ABKBSTDAT:,:ABKRECHADR:,:ABKAUFTTXT1:,:ABKAUFTTXT2:,:ABKZENTREG:,:ABKTEXTE11:,:ABKTEXTE12:,:ABKTEXTE13:,:ABKTEXTE14:,:ABKTEXTE21:,:ABKTEXTE22:,:ABKTEXTE23:,:ABKTEXTE24:,:ABKAENDZL:,:ABKAENDBEN:,:ABKAENDDAT:,:ABKNEUBEN:,:ABKNEUDAT:,:ABKDIVARTKZ:,:ABKAGKKZ:,:ABKKDKONTR:,:ABKSTKZL:,:ABKCOMPKZ:,:ABKFILLER:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData); 
                    break;
                case "FLT":
                    or1.CommandText = "INSERT INTO ABKOPF ( ABKMANDANT,ABKAUFKRS,ABKAUFLFD,ABKAUFART,ABKKUNDNR,ABKWERK,ABKABT,ABKVTRNR,ABKAEDAT,ABKKDAUFTNR,ABKKDAUFDAT,ABKKDZEICH,ABKKDSB,ABKARTSB,ABKORDER,ABKSPED,ABKVERSART,ABKVERPART,ABKVERSADR,ABKDIVADR,ABKBSTADR,ABKBSTDAT,ABKRECHADR,ABKAUFTTXT1,ABKAUFTTXT2,ABKZENTREG,ABKTEXTE11,ABKTEXTE12,ABKTEXTE13,ABKTEXTE14,ABKTEXTE21,ABKTEXTE22,ABKTEXTE23,ABKTEXTE24,ABKAENDZL,ABKAENDBEN,ABKAENDDAT,ABKNEUBEN,ABKNEUDAT,ABKDIVARTKZ,ABKAGKKZ,ABKKDKONTR,ABKSTKZL,ABKCOMPKZ,ABKFILLER)"
                    + " VALUES (:ABKMANDANT:,:ABKAUFKRS:,:ABKAUFLFD:,:ABKAUFART:,:ABKKUNDNR:,:ABKWERK:,:ABKABT:,:ABKVTRNR:,:ABKAEDAT:,:ABKKDAUFTNR:,:ABKKDAUFDAT:,:ABKKDZEICH:,:ABKKDSB:,:ABKARTSB:,:ABKORDER:,:ABKSPED:,:ABKVERSART:,:ABKVERPART:,:ABKVERSADR:,:ABKDIVADR:,:ABKBSTADR:,:ABKBSTDAT:,:ABKRECHADR:,:ABKAUFTTXT1:,:ABKAUFTTXT2:,:ABKZENTREG:,:ABKTEXTE11:,:ABKTEXTE12:,:ABKTEXTE13:,:ABKTEXTE14:,:ABKTEXTE21:,:ABKTEXTE22:,:ABKTEXTE23:,:ABKTEXTE24:,:ABKAENDZL:,:ABKAENDBEN:,:ABKAENDDAT:,:ABKNEUBEN:,:ABKNEUDAT:,:ABKDIVARTKZ:,:ABKAGKKZ:,:ABKKDKONTR:,:ABKSTKZL:,:ABKCOMPKZ:,:ABKFILLER:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }
            Connect2Proxy(or1);
        } 
        public void DeleteABKOPF(string client, string krs, string lfd)
        {
            
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM ABKOPF WHERE  "
                      + "  ABKMANDANT=:ABKMANDANT AND ABKAUFKRS=:ABKAUFKRS AND ABKAUFLFD=:ABKAUFLFD";
            or1.Parameters.Add("ABKMANDANT", OracleType.NVarChar).Value = client;
            or1.Parameters.Add("ABKAUFKRS", OracleType.NVarChar).Value = krs;
            or1.Parameters.Add("ABKAUFLFD", OracleType.NVarChar).Value = lfd;
            Connect2Proxy(or1);
        }
    }
}
